//
//  HEReportTitleInputCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/18.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEReportTitleInputCell.h"

@interface HEReportTitleInputCell ()<QMUITextFieldDelegate>

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) QMUITextField *inputTF;
@property (nonatomic, strong) UIImageView *arrowView;

@end

@implementation HEReportTitleInputCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.qmui_borderPosition = QMUIViewBorderPositionBottom;
        self.qmui_borderWidth = 1;
        self.qmui_borderColor = CSplitLineColor;
        [self initUI];
    }
    return self;
}

- (void)initUI {
     
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYFont(17);
    _titleLb.textColor = CNavLightBlackColor;
    _titleLb.numberOfLines = 0;
    [self.contentView addSubview:_titleLb];
    
    
    _inputTF = [[QMUITextField alloc] init];
    _inputTF.delegate = self;
    _inputTF.placeholder = @"请输入";
    _inputTF.font = DYFont(17);
    _inputTF.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_inputTF];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_inputTF.mas_left).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
     
    _arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 8, 12)];
    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
    _arrowView.image = IMAGE_NAMED(@"go_gray");
    [self.contentView addSubview:_arrowView];
    
    [_inputTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
        make.width.mas_offset(KScreenWidth*0.6);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    _titleLb.text = fiterModel.leftTitle;
    _inputTF.enabled = fiterModel.enable;
    _inputTF.keyboardType = fiterModel.keyboardType;
    _inputTF.placeholder = fiterModel.placeHolder;
    _inputTF.text = [formModel valueForKey:fiterModel.tableKey];
    _inputTF.textColor = fiterModel.contentColor;
    _titleLb.font = fiterModel.leftFont;
    _inputTF.font = fiterModel.contentFont;

    self.accessoryView = _arrowView;

    if (fiterModel.showArrow) {
        self.accessoryView = _arrowView;
        self.accessoryView.hidden = NO;
    }else {
        self.accessoryView.hidden = YES;
        self.accessoryView = [UIView new];
    }
    
}

- (void)configCellWithModel:(id)model fiterModel:(GDFiterCellModel *)fiterModel indexPath:(NSIndexPath *)indexPath {
    self.fiterModel = fiterModel;
    _titleLb.text = fiterModel.leftTitle;
    _inputTF.enabled = fiterModel.enable;
    _inputTF.keyboardType = fiterModel.keyboardType;
    _inputTF.placeholder = fiterModel.placeHolder;
    _inputTF.text = [self.formModel valueForKey:fiterModel.tableKey];
    _inputTF.textColor = fiterModel.contentColor;
    _titleLb.font = fiterModel.leftFont;
    _inputTF.font = fiterModel.contentFont;
    
    self.accessoryView = _arrowView;

    if (fiterModel.showArrow) {
        self.accessoryView = _arrowView;
        self.accessoryView.hidden = NO;
    }else {
        self.accessoryView.hidden = YES;
        self.accessoryView = [UIView new];
    }
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    [self.formModel setValue:text forKey:self.fiterModel.tableKey]; // 将textField中的值赋给_formModel
    return YES;
}
 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
